$(document).ready(function(){
 
	$('.arriba_button').click(function () { 
	  window.scrollTo(0,0);
	  return false;
	});
	
	$('#nav > li').hover(						 
	function(){
		$('#nav > li > ul').hide();
		$(this).find('> a').addClass('active').next().show();
		$(this).addClass('over');
	},
	function(){
		$(this).find('> a').removeClass('active').next().hide();
		$('#nav > li.active > ul').show();
		$(this).removeClass('over');
	}
	);
	
	$('#nav > li.active > ul').show();
	
	
	$('#ctl00_ContentPlaceHolder1_grilla tr').hover(
	function () {
		$(this).addClass('hover');
	}, 
	function () {
		$(this).removeClass('hover');
	}
	);
	
		///-----------------
   $('#ctl00_ContentPlaceHolder1_txtFechaInicio').keypress(function(e){  
 
           var  keyAscii = e.which;
           var texto = this.value;
           if( ((texto.length == 2) || (texto.length) == 5) &&  keyAscii != 8 && keyAscii != 0  ) {
   	          if(keyAscii<48 || keyAscii>57 ){
			        return false;
	          }else{
			        this.value = this.value + "/";
	          }
           } else{
              if( ( keyAscii<48 || keyAscii>57 ) &&  keyAscii != 8 && keyAscii != 0 && keyAscii != 47){
		        return false;
              }
           }
      }  
    );
    
     $('#ctl00_ContentPlaceHolder1_txtFechaFin').keypress(function(e) {  
 
           var  keyAscii = e.which;
           var texto = this.value;
           if( ((texto.length == 2) || (texto.length) == 5) &&  keyAscii != 8 && keyAscii != 0  ) {
   	          if(keyAscii<48 || keyAscii>57 ){
			        return false;
	          }else{
			        this.value = this.value + "/";
	          }
           } else{
              if( ( keyAscii<48 || keyAscii>57 ) &&  keyAscii != 8 && keyAscii != 0 && keyAscii != 47){
		        return false;
              }
           }
      }  
    );
    
     $('#ctl00_ContentPlaceHolder1_txtfecha').keypress(function(e) {  
 
           var  keyAscii = e.which;
           var texto = this.value;
           if( ((texto.length == 2) || (texto.length) == 5) &&  keyAscii != 8 && keyAscii != 0  ) {
   	          if(keyAscii<48 || keyAscii>57 ){
			        return false;
	          }else{
			        this.value = this.value + "/";
	          }
           } else{
              if( ( keyAscii<48 || keyAscii>57 ) &&  keyAscii != 8 && keyAscii != 0 && keyAscii != 47){
		        return false;
              }
           }
      }  
    );
    
     $('#ctl00_ContentPlaceHolder1_idfechas').keypress(function(e) {  
 
           var  keyAscii = e.which;
           var texto = this.value;
           if( ((texto.length == 2) || (texto.length) == 5) &&  keyAscii != 8 && keyAscii != 0  ) {
   	          if(keyAscii<48 || keyAscii>57 ){
			        return false;
	          }else{
			        this.value = this.value + "/";
	          }
           } else{
              if( ( keyAscii<48 || keyAscii>57 ) &&  keyAscii != 8 && keyAscii != 0 && keyAscii != 47){
		        return false;
              }
           }
      }  
    );
    
         $('#ctl00_ContentPlaceHolder1_fechaFoto').keypress(function(e) {  
 
           var  keyAscii = e.which;
           var texto = this.value;
           if( ((texto.length == 2) || (texto.length) == 5) &&  keyAscii != 8 && keyAscii != 0  ) {
   	          if(keyAscii<48 || keyAscii>57 ){
			        return false;
	          }else{
			        this.value = this.value + "/";
	          }
           } else{
              if( ( keyAscii<48 || keyAscii>57 ) &&  keyAscii != 8 && keyAscii != 0 && keyAscii != 47){
		        return false;
              }
           }
      }  
    );
    
         $('#ctl00_ContentPlaceHolder1_fecha_1').keypress(function(e) {  
 
           var  keyAscii = e.which;
           var texto = this.value;
           if( ((texto.length == 2) || (texto.length) == 5) &&  keyAscii != 8 && keyAscii != 0  ) {
   	          if(keyAscii<48 || keyAscii>57 ){
			        return false;
	          }else{
			        this.value = this.value + "/";
	          }
           } else{
              if( ( keyAscii<48 || keyAscii>57 ) &&  keyAscii != 8 && keyAscii != 0 && keyAscii != 47){
		        return false;
              }
           }
      }  
    );
    
         $('#ctl00_ContentPlaceHolder1_fecha_2').keypress(function(e) {  
 
           var  keyAscii = e.which;
           var texto = this.value;
           if( ((texto.length == 2) || (texto.length) == 5) &&  keyAscii != 8 && keyAscii != 0  ) {
   	          if(keyAscii<48 || keyAscii>57 ){
			        return false;
	          }else{
			        this.value = this.value + "/";
	          }
           } else{
              if( ( keyAscii<48 || keyAscii>57 ) &&  keyAscii != 8 && keyAscii != 0 && keyAscii != 47){
		        return false;
              }
           }
      }  
    );
    
    ///        
    
    
    
    
      $('#ctl00_ContentPlaceHolder1_txtHi').keypress(function(e) 
     {  
 
           var  keyAscii = e.which;
           var texto = this.value;
           if( ((texto.length == 2)) &&  keyAscii != 8 && keyAscii != 0  ) {
   	          if(keyAscii<48 || keyAscii>57 ){
			        return false;
	          }else{
			        this.value = this.value + ":";
	          }
           } else{
              if( ( keyAscii<48 || keyAscii>57 ) &&  keyAscii != 8 && keyAscii != 0 && keyAscii != 58){
		        return false;
              }
           }
      }  
    );
    
    $('#ctl00_ContentPlaceHolder1_txtHF').keypress(function(e) 
     {  
 
           var  keyAscii = e.which;
           var texto = this.value;
           if( ((texto.length == 2)) &&  keyAscii != 8 && keyAscii != 0  ) {
   	          if(keyAscii<48 || keyAscii>57 ){
			        return false;
	          }else{
			        this.value = this.value + ":";
	          }
           } else{
              if( ( keyAscii<48 || keyAscii>57 ) &&  keyAscii != 8 && keyAscii != 0 && keyAscii != 58 ){
		        return false;
              }
           }
      }  
    );  
    
    $('#ctl00_ContentPlaceHolder1_txtHoraIni').keypress(function(e) 
    {  
 
           var  keyAscii = e.which;
           var texto = this.value;
           if( ((texto.length == 2)) &&  keyAscii != 8 && keyAscii != 0  ) {
   	          if(keyAscii<48 || keyAscii>57 ){
			        return false;
	          }else{
			        this.value = this.value + ":";
	          }
           } else{
              if( ( keyAscii<48 || keyAscii>57 ) &&  keyAscii != 8 && keyAscii != 0 && keyAscii != 58 ){
		        return false;
              }
           }
      }  
    );
    
    
     $('#ctl00_ContentPlaceHolder1_txtHoraFin').keypress(function(e) 
     {  
 
           var  keyAscii = e.which;
           var texto = this.value;
           
           if( ((texto.length == 2)) &&  keyAscii != 8 && keyAscii != 0  ) {
   	          if(keyAscii<48 || keyAscii>57 ){
			        return false;
	          }else{
			        this.value = this.value + ":";
	          }
           } else{
              if( ( keyAscii<48 || keyAscii>57 ) &&  keyAscii != 8 && keyAscii != 0 && keyAscii != 58 ){
		        return false;
              }
           }
      }  
    );
    
    
//      $('#ctl00_ContentPlaceHolder1_txtOrden1').keypress(function(e) 
//     {  
//      
//           var valid = "0123456789";
//           var key = String.fromCharCode(e.which);
//           if (valid.indexOf(key) == "-1") return false;
//      }  
//    );  

      $('#ctl00_ContentPlaceHolder1_txtOrden').keypress(function(e) 
     {  
           var valid = "0123456789";
           var key = String.fromCharCode(e.which);
           if(e.which == 8) return true;
            
           if (valid.indexOf(key) == "-1") return false;
      }  
    );  
    
      $('#ctl00_ContentPlaceHolder1_txtValor').keypress(function(e) 
     {  
           var valid = "0123456789";
           var key = String.fromCharCode(e.which);
           
           if(e.which == 8) return true;
           
           if (valid.indexOf(key) == "-1") return false;
      }  
    );  
    


     
	///-----------------
	$('#ctl00_ContentPlaceHolder1_dgUsuario tr').hover(
	function () {
		$(this).addClass('hover');
	}, 
	function () {
		$(this).removeClass('hover');
	}
	);
	///-----------------
	
	$('#show').toggle(
	function () {
            $('#form_search').show();
            $(this).addClass('arrow_top');
            $(this).attr("title","Close");
	},
	function () {
			$('#form_search').hide();
			$(this).removeClass('arrow_top');
			$(this).attr("title","Open");
	}
	);
	
 	 $('.list_links li').hover(
	  function () {
		$(this).addClass('bg_link');
	  }, 
	  function () {
		$(this).removeClass('bg_link');
	  }
	);
	 
 
	/*----------------------------*/
	 $("td .checkear > input").click(function() {
        if(this.checked) { $(this).parents('tr').addClass('over'); }
		else { $(this).parents('tr').removeClass('over'); }
    });
    
    
    $('#ctl00_ContentPlaceHolder1_grilla_ctl01_chkMarcarAll').click(function () {			
		$(this).parents('table').find('td .checkear > input').attr('checked', this.checked);
		if(this.checked) { $('td .checkear').parents('tr').addClass('over'); }
		else { $('td .checkear').parents('tr').removeClass('over'); }
	});
	  
	/*----------------------------*/
	
	$('td .check').click(function(){
		if(this.checked) { $(this).parents('tr').addClass('over'); }
		else { $(this).parents('tr').removeClass('over'); }
	});
	
	$('.close_box').click(function() {
		$(this).parents('.featured_top').hide();						  	
		return false;
	});
	$('.cierraMensaje').click(function() {
	     $('.MensajeMedio').hide();		
	     $('.Mensajetexto').hide();					  	
		return false;
	});
	
	$('.close_message').click(function() {
		$(this).parents('p').hide();						  	
		return false;
	});

	$('.eliminar, .eliminar_grafico').click( function() {
		switch( $('td input:checked').length ){
			case 0 : 
				$('#seleccionado').hide();
				
				$('#seleccionado_varios').hide();
				$('#no_seleccionado').show();
				return false;
				break;
				
			case 1 : 
				$('#seleccionado').show();
				$('#seleccionado_varios').hide();
				$('#no_seleccionado').hide();
				return false;					
				break;
			default : 
				$('#seleccionado').hide();
				$('#seleccionado_varios').show();
				$('#no_seleccionado').hide();
				break;
		}								   
	});
	
	$('.btn_si').click( 
	
	function() { 
	    var lsId='';
	    var lsIndicador='';
	    var idpag=$("#hidModulo").get(0).value;
	    var max = $('#ctl00_ContentPlaceHolder1_grilla tr').length;  
	    	    
	    for ( i = 0; i < max - 1; i++ )
        {   
            if ($("#chkElegir"+i).attr("checked"))
            {
                lsId = lsId + ',' + $("#hidId"+i).get(0).value;
            }
            
        }
          
        var lsRestaurar = $("#hidRestaurar").get(0).value;
         
        var cadena = location.pathname + "";
        cadena = cadena.substring(1, cadena.length);
        cadena = "/" + cadena.substring(0,cadena.indexOf("/", cadena.indexOf("/") + 1 ) );
        
        //alert(cadena);
         
        location.href = '../Eliminar.aspx?hidModulo='+idpag+'&Id=' + lsId + '&R=' + lsRestaurar;
        
	});
	
	//formulario
	$('input[type="text"]').addClass("idleField");
	$('input[type="password"]').addClass("idleField");
   
    $('input[type="text"]').focus(function() {
        $(this).removeClass("idleField").addClass("focusField");
    
    });
    $('input[type="text"]').blur(function() {
        $(this).removeClass("focusField").addClass("idleField");
        
    });
    
    $('input[type="password"]').focus(function() {
        $(this).removeClass("idleField").addClass("focusField");
    
    });
    $('input[type="password"]').blur(function() {
        $(this).removeClass("focusField").addClass("idleField");
        
    });
    
    $('select').addClass("idleSelect");
     
    
});